var vilplus = new (function() {
	var logger = new Logger("vilplus");
	var filterResult = {};
	var filterConfig = new Config();
	this.initialized = false;
	this.onLoad = function() {
		// initialization code
		logger.debug("initializing");
		// load config
		filterConfig.load();
		// initialized
		this.initialized = true;
		logger.debug("initialized");
	};
	this.processContentLoaded = function(e) {
		var safeDoc = e.target;
		logger.debug("DOMContentLoaded: " + safeDoc.location.href);
		doContentLoaded(safeDoc);
	}
	this.getFilterResult = function(docLoc) {
		return filterResult[docLoc];
	}
	var doContentLoaded = function(safeDoc) {
		var docLoc = safeDoc.location.href;
		var filter = filterConfig.getFilter(docLoc);
		if (filter) {
			var safeWin = safeDoc.defaultView;
			safeWin.addEventListener("unload", function(e) {
				doWindowUnload(e, docLoc);
			}, false);
			if (filterResult[docLoc]) {
				// release references of last result
				delete filterResult[docLoc];
			}
			filterResult[docLoc] = new FilterRunner(filter, safeDoc).run();
			logger.debug("filter loaded for: " + docLoc);
		} else {
			logger.debug("filter not found for: " + docLoc);
		}
		var viewer = _gel("VILViewer");
		if (viewer && !viewer.collapsed) {
			VILViewerUI.refreshImages();
		}
	}
	var doWindowUnload = function(e, docLoc) {
		logger.debug("doWindowUnload: " + docLoc);
		if (filterResult[docLoc]) {
			// release references of last result
			var res = (delete filterResult[docLoc]);
			logger.debug("result for docLoc deleted: " + res);
		}
		_gel("VILViewer").clear();
	}
});
